package com.eachonline.smart.service.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eachonline.core.Pagination;
import com.eachonline.mapper.GenericMapper;
import com.eachonline.service.GenericServiceImpl;
import com.eachonline.smart.mapper.SmartArtcileMapper;
import com.eachonline.smart.model.SmartArtcile;
import com.eachonline.smart.model.SmartArtcileExample;
import com.eachonline.smart.model.base.BaseSmartArtcileExample.Criteria;
import com.eachonline.smart.service.ArticleService;
import com.eachonline.util.StringUtil;
@Service
public class ArticleServiceImp extends GenericServiceImpl<SmartArtcile, SmartArtcileExample, String> implements ArticleService {

	@Autowired
	private SmartArtcileMapper  smartArticleMapper;

	@Override
	protected GenericMapper<SmartArtcile, SmartArtcileExample, String> getGenericMapper() {
		// TODO Auto-generated method stub
		return this.smartArticleMapper;
	}

	@Override
	public Pagination<SmartArtcile> queryArticleList(int start, int pageSize,
			String site, String articleName, String teacherId,String articleCategoryCode) {
		// TODO Auto-generated method stub
		SmartArtcileExample artEx=new SmartArtcileExample();
    	Criteria cri=artEx.createCriteria();
    	if(StringUtil.isNotEmpty(articleName))
    	{
    		cri.andArticleNameLike("%"+articleName+"%");
    	}
    	
    	if(StringUtil.isNotEmpty(articleCategoryCode))
    	{
    		cri.andArticleCategoryCodeLike("%"+articleCategoryCode+"%");
    	}
		
    	if(StringUtil.isNotEmpty(site))
    	{
    		cri.andArticleSiteEqualTo(site);
    	}
    	
    	if(StringUtil.isNotEmpty(teacherId))
    	{
    		cri.andTeacherIdEqualTo(teacherId);
    	}
		return queryByPage(artEx, start, pageSize, " create_time,study_num desc ");
	}
	
	
	@Override
	public Pagination<SmartArtcile> queryManageArticleList(int start, int pageSize,
			String site, String articleName, String status,String articleCategoryCode) {
		// TODO Auto-generated method stub
		SmartArtcileExample artEx=new SmartArtcileExample();
    	Criteria cri=artEx.createCriteria();
    	if(StringUtil.isNotEmpty(articleName))
    	{
    		cri.andArticleNameLike("%"+articleName+"%");
    	}
    	
    	if(StringUtil.isNotEmpty(articleCategoryCode))
    	{
    		cri.andArticleCategoryCodeLike("%"+articleCategoryCode+"%");
    	}
		
    	if(StringUtil.isNotEmpty(site))
    	{
    		cri.andArticleSiteEqualTo(site);
    	}
    	
    	if(StringUtil.isNotEmpty(status))
    	{
    		cri.andCheckStatusEqualTo(status);
    	}
		return queryByPage(artEx, start, pageSize, " create_time desc ");
	}
	

	@Override
	public Pagination<SmartArtcile> queryTeacherArticleList(int start,
			int pageSize, String status, String teacherId) {
		// TODO Auto-generated method stub
		SmartArtcileExample artEx=new SmartArtcileExample();
    	Criteria cri=artEx.createCriteria();
    	if(StringUtil.isNotEmpty(status))
    	{
    		cri.andCheckStatusEqualTo(status);
    	}
    	
    	if(StringUtil.isNotEmpty(teacherId))
    	{
    		cri.andTeacherIdEqualTo(teacherId);
    	}
		return queryByPage(artEx, start, pageSize, " create_time,study_num desc ");
	}

	@Override
	public Pagination<SmartArtcile> queryTeacherArticleList(int start,
			int pageSize, String status, String teacherId, String categroyCode,String source) {
		// TODO Auto-generated method stub
				SmartArtcileExample artEx=new SmartArtcileExample();
		    	Criteria cri=artEx.createCriteria();
		    	if(StringUtil.isNotEmpty(status))
		    	{
		    		cri.andCheckStatusEqualTo(status);
		    	}
		    	
		    	if(StringUtil.isNotEmpty(teacherId))
		    	{
		    		cri.andTeacherIdEqualTo(teacherId);
		    	}
		    	if(StringUtil.isNotEmpty(source))
		    	{
		    		cri.andArticleSourceEqualTo(source);
		    	}
		    	
		    	if(StringUtil.isNotEmpty(categroyCode))
		    	{
		    		cri.andArticleCategoryCodeLike(categroyCode+"%");
		    	}
				return queryByPage(artEx, start, pageSize, " create_time,study_num desc ");
	}
	
	
}